home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / ptv3n5.zip / GETEVENT.SRC < prev    next >
Text File  |  1992-09-01  |  2KB  |  63 lines

  1. PROCEDURE TEditorApp.GetEvent(VAR Event: TEvent);
  2. VAR
  3.   { Used to allocate the help window. }
  4.   W: PWindow;
  5.   { The help object with its hypertext engine, 
  6.     window handling, etc. }
  7.   HFile: PHelpFile;
  8.   { Lets you save the current help context to a stream with
  9.     the rest of your application on a desktop file. }
  10.   HelpStrm: PDosStream;
  11. CONST
  12.   { Prevents opening two help files at once. }
  13.   HelpInUse: Boolean = False;
  14. BEGIN
  15.   { Always make this the first statement of your GetEvent
  16.     replacement. }
  17.   TApplication.GetEvent(Event);
  18.   { See if help has been requested. }
  19.   CASE Event.What OF
  20.     evCommand:
  21.       IF (Event.Command = cmHelp) AND NOT HelpInUse THEN BEGIN
  22.         { Help has been requested.
  23.           Disallow use of multiple help files. }
  24.         HelpInUse := True;
  25.         { Determine the help file's name based on the
  26.           application's name. }
  27.         HelpStrm := New(PDosStream, Init(CalcHelpName,
  28.                         stOpenRead));
  29.         { Open the help file object. }
  30.         HFile := New(PHelpFile, Init(HelpStrm));
  31.         IF HelpStrm^.Status <> stOk THEN BEGIN
  32.           { If there was a problem, e.g., the help file
  33.             couldn't be found, let the user know. }
  34.           MessageBox('Could not open help file.', nil,
  35.                      mfError + mfOkButton);
  36.           { Deallocate the help file's resources. }
  37.           Dispose(HFile, Done);
  38.         END
  39.         ELSE BEGIN
  40.           { There was no problem allocating the help file.
  41.             Allocate the help window object. }
  42.           W := New(PHelpWindow,Init(HFile, GetHelpCtx));
  43.           IF ValidView(W) <> nil THEN BEGIN
  44.             { If there was enough memory to allocate the
  45.               help object, attach it to the application's
  46.               window list. }
  47.             ExecView(W);
  48.             { After the user has exited help, deallocate
  49.               the help object. }
  50.             Dispose(W, Done);
  51.           END;
  52.           { Remove the help message from the event queue. }
  53.           ClearEvent(Event);
  54.         END;
  55.         { Signal that a help window may now be opened. }
  56.         HelpInUse := FALSE;
  57.       END;
  58.     evMouseDown:
  59.       IF Event.Buttons <> 1 THEN
  60.         Event.What := evNothing;
  61.   END; { end case }
  62. END;
  63.